package com.juphoon.mockdata.data.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.juphoon.mockdata.util.Utils;
import lombok.Data;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class E06RequestDTO {
    @JacksonXmlProperty(localName = "SYS_HEAD")
    @JsonProperty("SYS_HEAD")
    private E06SysHead.Request sys_head = new E06SysHead.Request();
    @JacksonXmlProperty(localName = "APP_HEAD")
    @JsonProperty("APP_HEAD")
    private Map<String, Object> app_head = new HashMap<>();
    @JacksonXmlProperty(localName = "LOCAL_HEAD")
    @JsonProperty("LOCAL_HEAD")
    private Map<String, Object> local_head = new HashMap<>();
    private static int index = 0;

    public void genCommonSysHead(String code, String scene, String version) {
        sys_head.setServiceCode(code);
        sys_head.setServiceScene(scene);
        sys_head.setServiceVersion(version);
        sys_head.setConsumerId("800833");
        sys_head.setTranDate(Utils.getTime("yyyyMMdd"));
        sys_head.setTranTimestamp(Utils.getTime("HHmmss"));
        sys_head.setLegalEntityCode("1000");
        sys_head.setSourceBranchNo("800833");
        sys_head.setBranchId("88888");
        sys_head.setOrgSysId("800833");
        sys_head.setUserId("82812");
        sys_head.setWsId("TTYRTC");
        sys_head.setAuthUsers(Collections.singletonList(E06SysHead.Request.AuthUser.builder()
                .authUserId("82812").build()));
        String consumerSeqNo = "800833" +
                Utils.getTime("yyyyMMdd") +
                "00" +
                Utils.getTime("HHmmssSSS" + index);
        String traceId = "800833" +
                Utils.getTime("yyyyMMddHHMMss") +
                "00" +
                Utils.getTime("HHmmssSSS" + index);
        index++;
        if (index > 8) {
            index = 0;
        }
        sys_head.setTraceId(traceId);
        sys_head.setConsumerSeqNo(consumerSeqNo);
    }

    @Data
    @JacksonXmlRootElement(localName = "service")
    public static class Common extends E06RequestDTO {
        @JacksonXmlProperty(localName = "BODY")
        @JsonProperty("BODY")
        private Map<String, Object> body = new HashMap<>();
    }

    //特殊
    //查询结构化产品
    @Data
    @JacksonXmlRootElement(localName = "service")
    public static class DepositList extends E06RequestDTO {
        @JacksonXmlProperty(localName = "BODY")
        private Body body;

        @Data
        public static class Body {
            @JacksonXmlProperty(localName = "REPEAT_NUM")
            private String repeatNum;
            @JacksonXmlProperty(localName = "CHANNEL_CODE")
            private String channelCode;
            @JacksonXmlProperty(localName = "PRODUCT_MODEL")
            private String productModel;
            @JacksonXmlProperty(localName = "TERM")
            private String term;
            @JacksonXmlProperty(localName = "PRODUCT_NAME")
            private String productName;
            @JacksonXmlElementWrapper(localName = "LIST_ARRAY")
            @JacksonXmlProperty(localName = "struct")
            private List<ListDTO> list;

            @Data
            public static class ListDTO {
                @JacksonXmlProperty(localName = "SETTLE_ACCT_NO")
                private String settleAcctNo;
            }
        }
    }

    //查询结构化产品
    @Data
    @JacksonXmlRootElement(localName = "service")
    public static class OperatorIncEcho extends E06RequestDTO {
        @JacksonXmlProperty(localName = "BODY")
        private Body body;

        @Data
        public static class Body {
            @JacksonXmlElementWrapper(localName = "DETAIL_ARRAY")
            @JacksonXmlProperty(localName = "struct")
            private List<ListDTO> list;

            @Data
            public static class ListDTO {
                @JacksonXmlProperty(localName = "EVENT_NO")
                private String eventNo;
                @JacksonXmlProperty(localName = "SUCC_FLAG")
                private String succFlag;
                @JacksonXmlProperty(localName = "REASON")
                private String reason;
            }
        }
    }

    //根据查客户银行卡号
    @Deprecated
    @Data
    @JacksonXmlRootElement(localName = "service")
    public static class QueryCustomer extends E06RequestDTO {
        @JacksonXmlProperty(localName = "BODY")
        private Body body;

        @Data
        public static class Body {
            @JacksonXmlProperty(localName = "QUERY_TYPE")
            private String queryType;
            @JacksonXmlProperty(localName = "CCY")
            private String ccy;
            @JacksonXmlProperty(localName = "ACCT_TYPE")
            private String acctType;
            @JacksonXmlProperty(localName = "GL_LEVEL")
            private String glLevel;
            @JacksonXmlProperty(localName = "REPEAT_NUM")
            private String repeatNum;
            @JacksonXmlProperty(localName = "DEPOSIT_PRODUCT_TYPE")
            private String depositProductType;
            @JacksonXmlProperty(localName = "ACCT_STATUS")
            private String acctStatus;

            @JacksonXmlElementWrapper(localName = "LIST_ARRAY")
            @JacksonXmlProperty(localName = "struct")
            private List<ListDTO> list;

            @Data
            public static class ListDTO {
                @JacksonXmlProperty(localName = "ACCT_NO")
                private String acctNo;
            }
        }
    }


}
